<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" scroll="no">
<%@ taglib prefix="ef" uri="control"%>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>角色</title>
<link rel="shortcut icon" href="${res}favicon.ico" type="image/x-icon" />
 <!--Basic Styles-->
<link href="../framework/css/font.css" rel="stylesheet" />
<link href="../framework/miniui/themes/material/miniui.css" rel="stylesheet" />
<link href="../framework/css/app.min.1.css" rel="stylesheet" type="text/css" />
<link href="../framework/css/app.min.2.css" rel="stylesheet" type="text/css" />
<script src="../framework/main.js" type="text/javascript"></script>
<style type="text/css">
.input-group-addon{width:80px;text-align: right;}
</style>
<script>
function onTreeClick(e){
	var code = e.getAttribute("cid");
	//if(code&&code!="null"){
		$G('TabFrame').contentWindow.changeRole(code||0);
	//}
}

function add(){
	mini.open({
		width : 530,
		height : 150,
		title : '@{Role.New}',
		url : "${ctx}mhr/roleAddDialog.jhtml?BranchInnerCode="+$V("BranchInnerCode"),
		onOk : addSave,
		onLoad : function(){
			try{
				$DW.$('#RoleName').focus();
			}catch(e){}
		}
	});
}

function addSave(){
	var dc = $DW.Form.getData('form2');
	if($DW.isValid() == false){
		return;
	}
	Server.sendRequest("Role.add",dc,function(response){
		if(response.Status == 1){
			top.mini.showTips({content:response.Message,state:'success'});
			node = mini.get("tree1").getNode(dc.get("RoleCode"));
			mini.get("tree1").selectNode(node);
			$D.close();
		}else{
			top.mini.warn(response.Message);
		}
	});
}
function del(){
	var code = Tree('tree1').currentNode && Tree('tree1').currentNode.el.getAttribute("cid");
	if(!code||code=="null" ){
		return;
	}
 	if(!code){
 		top.mini.showTips({content:'@{Common.PleaseSelectToDeleteRowFirst}',state:'info'});
		return ;
	}
 		mini.confirm("@{Role.ConfirmDelete} <b style='color:#F00'>"+code+"</b> ？",function(action){
		var dc = {RoleCode:code};
		 if (action == "ok") {
			Server.sendRequest("Role.del",dc,function(response){
				if(response.Status == 1){
					top.mini.showTips({content:response.Message,state:'success'});
					Cookie.set("Role.LastRoleCode","");
					window.location.reload();
				}else{
					top.mini.warn(response.Message);
				}
			});
		 };
	});
}

function edit(){
	if(!mini.get('tree1').getSelectedNode()){
		top.mini.showTips({content:'@{Framework.DataGrid.PleaseSelectFirst}',state:'info'});
		return ;
	}
	var code = mini.get('tree1').getSelectedNode();
	if(!code||code=="null"){
		top.mini.showTips({content:'@{Framework.DataGrid.PleaseSelectFirst}',state:'info'});
		return ;
	}
	mini.open({
		width : 530,
		height : 150,
		title : '@{Role.Edit}',
		url : "${ctx}mhr/roleAddDialog.jhtml?ID="+code,
		onOk : editSave,
		onLoad : function(){
			$DW.$('#RoleCode').disable();
			$DW.$('#BranchInnerCode').disable();
			try{
				$DW.$('#RoleName').focus();
			}catch(e){}
		}
	});
}

function editSave(){
	var dc = $DW.Form.getData('form2');
	if($DW.isValid() == false){
		return;
	}
	Server.sendRequest("Role.save",dc,function(response){
		if(response.Status == 1){
			top.mini.showTips({content:response.Message,state:'success'});
			node = mini.get("tree1").getNode(dc.get("RoleCode"));
			mini.get("tree1").selectNode(node);
			$D.close();
			$G('TabFrame').contentWindow.TabPage.getCurrentTab().onclick();
		}else{
			top.mini.warn(response.Message);
		}
	});
}
Page.onLoad(function(){
	$('#tree1 dt:eq(0)').click();
});
</script>
</head>
<body class="body-list">
<div class="mini-toolbar">
</div>
		<ul id="tree1" class="mini-tree" method="MemberRole.bindTree" style="height:100%;width:100%;" 
    		showTreeIcon="true" resultAsTree="false" textField="RoleName" idField="RoleCode" >        
		</ul>
		<input type="hidden" id="BranchInnerCode" value="${BranchInnerCode}"/> 	
		
</body>
</html>